package love.yuanmengrobot.attendancesystem.servlet;
/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:CHJY创幻
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/6/21 21:32
 */

import com.google.gson.Gson;
import love.yuanmengrobot.attendancesystem.dao.ClazzMemberDao;
import love.yuanmengrobot.attendancesystem.entity.Member;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

public class ClazzMemberServlet extends javax.servlet.http.HttpServlet {
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        System.out.println("post");

        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String id = request.getParameter("clazzid");
        String clazzname = request.getParameter("clazzname");
//仅跳转
        request.setAttribute("clazzid", id);
        request.setAttribute("clazzname", clazzname);
        request.getRequestDispatcher("clazzdesc.jsp").forward(request, response);

    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String id = request.getParameter("clazzid");
        System.out.println("get:" + id);

        //查询班级的成员,仅获取json数据
        ClazzMemberDao clazzMemberDao = new ClazzMemberDao();
        ArrayList<Member> list = clazzMemberDao.qureyClazzMemberById(id);
        PrintWriter pw = response.getWriter();
        if (list != null) {
            Gson gson = new Gson();
            pw.print(gson.toJson(list));
        }
        pw.flush();
        pw.close();
//        request.getRequestDispatcher("clazzdesc.jsp").forward(request, response);
    }

}
